from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker


guangzhou_region = ["越秀区", "天河区", "海珠区", "荔湾区",
                    "白云区", "番禺区", "黄埔区", "南沙区", "增城区", "花都区", "从化区"]
region_name_map = ["Yuexiu", "Tianhe", "Haizhu", "Liwan",
                    "Baiyun", "Panyu", "Huangpu", "Nansha", "Zengcheng", "Huadu", "Conghua"]
guangzhou_value = ["357", "216", "110", "105",
                   "102", "67", "42", "20", "25", "24", "10"]

name_shadow_map=dict(zip(guangzhou_region, region_name_map))
distance_shadow_map=dict(zip(guangzhou_region, guangzhou_value))
# print(name_shadow_map)

c = (
    Map()
    .add(
        series_name="广州",
        # data_pair=[list(z) for z in zip(guangzhou_region, guangzhou_value)],
        data_pair=[[name_shadow_map[z[0]], z[1]] for z in zip(guangzhou_region, guangzhou_value)],
        maptype="广州",
        name_map=name_shadow_map,
        zoom=1,
        label_opts=opts.LabelOpts(
            position="top",
            distance=0,
            font_size=5,
            formatter="{b}",
        ),
        is_map_symbol_show=True
    )
    # .set_series_opts(
    #     label_opts=opts.LabelOpts(is_show=False)
    # )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Map-广州地图"),
        visualmap_opts=opts.VisualMapOpts(
            min_=0,
            max_=400,
            range_text=["High", "Low"],
            range_color=["#DAE3F2", "#8FAED9", "#6A93CB", "#225FB3"],
            pos_left="20%",
            pos_bottom="10%",
            textstyle_opts=opts.TextStyleOpts(
                font_size=12
            )
        ),

    )
    .render("map_guangzhou.html")
)
